package com.seek.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.seek.commonutils.ResponseResult;
import com.seek.eduservice.entity.EduCourse;
import com.seek.eduservice.entity.EduTeacher;
import com.seek.eduservice.service.EduCourseService;
import com.seek.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: wml
 * @since: 2022/2/11 10:16
 */
@RestController
@RequestMapping("/eduservice/index")
public class IndexController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;

    // 查询前 8 条热门课程，前 4 名讲师
    @GetMapping("getPopularCourseAndTeacher")
    public ResponseResult getPopularCourseAndTeacher() {
        // 查询前 8 条热门课程
        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("id");
        courseQueryWrapper.last("limit 8");
        List<EduCourse> eduCourseList = eduCourseService.list(courseQueryWrapper);
        // 查询前 4 名讲师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> eduTeacherList = eduTeacherService.list(teacherQueryWrapper);
        return ResponseResult.ok().data("courseList", eduCourseList).data("teacherList", eduTeacherList);
    }
}
